///////////////////////////////////////////////////////////
//  ConditionAtm.cpp
//  Implementation of the Class ConditionAtm
//  Created on:      21-sep-2007 15:40:09
///////////////////////////////////////////////////////////

#include "ConditionAtm.h"
#include <iostream>

#define SIZE_PKCONDITIONATM 10
#define SIZE_CODE 5
#define SIZE_DATE 11
#define SIZE_DRCT 7
#define SIZE_DWPT 7
#define SIZE_HGHT 7
#define SIZE_MIXR 7
#define SIZE_PRES 7
#define SIZE_RELH 7
#define SIZE_SKNT 7
#define SIZE_TEMP 7
#define SIZE_THTA 7
#define SIZE_THTE 7
#define SIZE_THTV 10

#define SIZE_PKCONDITIONATM_SCHEMA 14
#define SIZE_CODE_SCHEMA 9
#define SIZE_DATE_SCHEMA 11
#define SIZE_DRCT_SCHEMA 4
#define SIZE_DWPT_SCHEMA 4
#define SIZE_HGHT_SCHEMA 4
#define SIZE_MIXR_SCHEMA 4
#define SIZE_PRES_SCHEMA 4
#define SIZE_RELH_SCHEMA 4
#define SIZE_SKNT_SCHEMA 4
#define SIZE_TEMP_SCHEMA 4
#define SIZE_THTA_SCHEMA 4
#define SIZE_THTE_SCHEMA 4
#define SIZE_THTV_SCHEMA 4

campo ConditionAtm::PK[2] = {{"PKConditionAtm",CHAR, SIZE_PKCONDITIONATM},{0,0,0}};
campo ConditionAtm::CODE[2] = {{"stationCode",CHAR, SIZE_CODE},{0,0,0}};
campo ConditionAtm::CODE_SAMPLE[2] = {{"sampleCode",CHAR, SIZE_CODE},{0,0,0}};
campo ConditionAtm::DATE[2] = {{"date",CHAR, SIZE_DATE},{0,0,0}};
campo ConditionAtm::DRCT[2] = {{"drct",CHAR, SIZE_DRCT},{0,0,0}};
campo ConditionAtm::DWPT[2] = {{"dwpt",CHAR, SIZE_DWPT},{0,0,0}};
campo ConditionAtm::HGHT[2] = {{"hght",CHAR, SIZE_HGHT},{0,0,0}};
campo ConditionAtm::MIXR[2] = {{"mixr",CHAR, SIZE_MIXR},{0,0,0}};
campo ConditionAtm::PRES[2] = {{"pres",CHAR, SIZE_PRES},{0,0,0}};
campo ConditionAtm::RELH[2] = {{"relh",CHAR, SIZE_RELH},{0,0,0}};
campo ConditionAtm::SKNT[2] = {{"sknt",CHAR, SIZE_SKNT},{0,0,0}};
campo ConditionAtm::TEMP[2] = {{"temp",CHAR, SIZE_TEMP},{0,0,0}};
campo ConditionAtm::THTA[2] = {{"thta",CHAR, SIZE_THTA},{0,0,0}};
campo ConditionAtm::THTE[2] = {{"thte",CHAR, SIZE_THTE},{0,0,0}};
campo ConditionAtm::THTV[2] = {{"thtv",CHAR, SIZE_THTV},{0,0,0}};

campo ConditionAtm::CONDITIONATM_SCHEMA[SIZE_CONDITIONATM_SCHEMA] = {{"PKConditionAtm",CHAR, SIZE_PKCONDITIONATM}, 
											{"stationCode",CHAR, SIZE_CODE}, 
											{"sampleCode",CHAR, SIZE_CODE}, 
											{"date",CHAR, SIZE_DATE}, 
											{"drct",CHAR, SIZE_DRCT}, 
											{"dwpt",CHAR, SIZE_DWPT}, 
											{"hght",CHAR, SIZE_HGHT}, 
											{"mixr",CHAR, SIZE_MIXR}, 
											{"pres",CHAR, SIZE_PRES}, 
											{"relh",CHAR, SIZE_RELH}, 
											{"sknt",CHAR, SIZE_SKNT}, 
											{"temp",CHAR, SIZE_TEMP}, 
											{"thta",CHAR, SIZE_THTA}, 
											{"thte",CHAR, SIZE_THTE}, 
											{"thtv",CHAR, SIZE_THTV},
											{0,0,0}};

#ifndef UNO
	#define UNO 1
#endif

#ifndef ZERO
	#define ZERO 0
#endif


ConditionAtm::ConditionAtm(){

}


ConditionAtm::~ConditionAtm(){

}

std::string ConditionAtm::getPKConditionAtm()
{
	return this->PKConditionAtm;
}

std::string ConditionAtm::getValor(std::string atribName){
	
	if (ConditionAtm::PK[0].nombre == atribName){
		return this->PKConditionAtm;
	}
	if (ConditionAtm::CODE[0].nombre == atribName){
		return this->stationCode;
	}
	if (ConditionAtm::DATE[0].nombre == atribName){
		return this->date;
	}
	if (ConditionAtm::DRCT[0].nombre == atribName){
		return this->drct;
	}
	if (ConditionAtm::DWPT[0].nombre == atribName){
		return this->dwpt;
	}
	if (ConditionAtm::HGHT[0].nombre == atribName){
		return this->hght;
	}
	if (ConditionAtm::MIXR[0].nombre == atribName){
		return this->mixr;
	}
	if (ConditionAtm::PRES[0].nombre == atribName){
		return this->pres;
	}
	if (ConditionAtm::RELH[0].nombre == atribName){
		return this->relh;
	}
	if (ConditionAtm::SKNT[0].nombre == atribName){
		return this->sknt;
	}
	if (ConditionAtm::TEMP[0].nombre == atribName){
		return this->temp;
	}
	if (ConditionAtm::THTA[0].nombre == atribName){
		return this->thta;
	}
	if (ConditionAtm::THTE[0].nombre == atribName){
		return this->thte;
	}
	if (ConditionAtm::THTV[0].nombre == atribName){
		return this->thtv;
	}
	return "";
}

std::string ConditionAtm::getKey(){
	return this->PKConditionAtm;
}

void ConditionAtm::setKey(std::string key){
	this->PKConditionAtm = key;
}

bool ConditionAtm::EsMayor(std::string atributte, Persistent *object)
{
	return (this->getValor(atributte) > object->getValor(atributte));
}

int ConditionAtm::getSchemaSize(){
	return  SIZE_CONDITIONATM_SCHEMA;
}


void ConditionAtm::loadAtribFromNode(XMLNode* node)
{
	listaXML::const_iterator j = node->hijos.begin();
	std::string nombreNodo;
	for(;j != node->hijos.end() ;j++)
	{
		nombreNodo=(*j)->getNombre();
		if (nombreNodo == "drct")
		{
			this->drct = (*j)->getContenido();
		}
		else
		{
			if (nombreNodo == "dwpt")
			{
				this->dwpt = (*j)->getContenido();
			}
			else
			{
				if (nombreNodo == "hght")
				{
					this->hght = (*j)->getContenido();
				}
				else
				{
					if (nombreNodo == "mixr")
					{
						this->mixr = (*j)->getContenido();
					}
					else
					{
						if (nombreNodo == "pres")
						{
							this->pres = (*j)->getContenido();
						}	
						else
						{
							if (nombreNodo == "relh")
							{
								this->relh = (*j)->getContenido();
							}
							else
							{
								if (nombreNodo == "sknt")
								{
									this->sknt = (*j)->getContenido();
								}
								else
								{
									if (nombreNodo == "temp")
									{
										this->temp = (*j)->getContenido();
									}
									else
									{
										if (nombreNodo == "thta")
										{
											this->thta = (*j)->getContenido();
										}
										else
										{
											if (nombreNodo == "thte")
											{
												this->thte = (*j)->getContenido();
											}
											else
											{
												if (nombreNodo == "thtv")
												{
													this->thtv = (*j)->getContenido();
												}
												else
												{
													if (nombreNodo == "relh")
													{
														this->relh = (*j)->getContenido();
													}
													else
													{
														if (nombreNodo == "sknt")
														{
															this->sknt = (*j)->getContenido();
														}
														else
														{
															if (nombreNodo == "temp")
															{
																this->temp = (*j)->getContenido();
															}
															else
															{
																if (nombreNodo == "thta")
																{
																	this->thta = (*j)->getContenido();
																}
																else
																{
																	if (nombreNodo == "thte")
																	{
																		this->thte = (*j)->getContenido();
																	}
																	else
																	{
																		if (nombreNodo == "thtv")
																		{
																			this->thtv = (*j)->getContenido();
																		}
																	}
																}
															}	
														}
													}
												}
											}
										}	
									}	
								}
							}
						}
					}
				}
			}
		}
	}
}

//Setters 

void ConditionAtm::setStationCode(std::string stationCode){
	this->stationCode=stationCode;
}

void ConditionAtm::setDate(std::string date){
	this->date=date;
}

void ConditionAtm::setDrct(std::string drct)
{
	this->drct=drct;
}
void ConditionAtm::setDwpt(std::string dwpt)
{
	this->dwpt=dwpt;
}
void ConditionAtm::setHght(std::string hght)
{
	this->hght=hght;
}
void ConditionAtm::setMixr(std::string mixr)
{
	this->mixr=mixr;
}
void ConditionAtm::setPres(std::string pres)
{
	this->pres=pres;
}
void ConditionAtm::setRelh(std::string relh)
{
	this->relh=relh;
}
void ConditionAtm::setSknt(std::string sknt)
{
	this->sknt=sknt;
}
void ConditionAtm::setSampleCode(std::string code)
{
	this->sampleCode=code;
}
void ConditionAtm::setTemp(std::string temp)
{
	this->temp=temp;
}
void ConditionAtm::setThta(std::string thta)
{
	this->thta=thta;
}
void ConditionAtm::setThte(std::string thte)
{
	this->thte=thte;
}
void ConditionAtm::setThtv(std::string thtv)
{
	this->thtv=thtv;
}

void ConditionAtm::setPKConditionAtm(std::string pk)
{
	this->PKConditionAtm = pk;
}

//GETTERS

std::string ConditionAtm::getDate()
{
	return this->date;
}
std::string ConditionAtm::getStationCode()
{
	return this->stationCode;
}
std::string ConditionAtm::getDrct()
{
	return this->drct;
}
std::string ConditionAtm::getDwpt()
{
	return this->dwpt;
}
std::string ConditionAtm::getHght()
{
	return this->hght;
}
std::string ConditionAtm::getMixr()
{
	return this->mixr;
}
std::string ConditionAtm::getSampleCode()
{
	return this->sampleCode;
}
std::string ConditionAtm::getPres()
{
	return this->pres;
}
std::string ConditionAtm::getRelh()
{
	return this->relh;
}
std::string ConditionAtm::getSknt()
{
	return this->sknt;
}
std::string ConditionAtm::getTemp()
{
	return this->temp;
}
std::string ConditionAtm::getThta()
{
	return this->thta;
}
std::string ConditionAtm::getThte()
{
	return this->thte;
}
std::string ConditionAtm::getThtv()
{
	return this->thtv;
}

campo* ConditionAtm::getSchema()
{
	return ConditionAtm::CONDITIONATM_SCHEMA;
}

campo* ConditionAtm::getPrimaryKey()
{
	return ConditionAtm::PK;
}

void ConditionAtm::loadRegistro(void* registro)
{
	campo* esquema = NULL;
	
	char ptrPKConditionAtm[SIZE_PKCONDITIONATM + UNO];
	char ptrStationCode[SIZE_CODE + UNO];
	char ptrSampleCode[SIZE_CODE + UNO];
	char ptrDate[SIZE_DATE + UNO];
	char ptrDrct[SIZE_DRCT + UNO];
	char ptrDwpt[SIZE_DWPT + UNO];
	char ptrHght[SIZE_HGHT + UNO];
	char ptrMixr[SIZE_MIXR + UNO];
	char ptrPres[SIZE_PRES + UNO];
	char ptrRelh[SIZE_RELH + UNO];
	char ptrSknt[SIZE_SKNT + UNO];
	char ptrTemp[SIZE_TEMP + UNO];
	char ptrThta[SIZE_THTA + UNO];
	char ptrThte[SIZE_THTE + UNO];
	char ptrThtv[SIZE_THTV + UNO];

	memset(ptrPKConditionAtm, ZERO, SIZE_PKCONDITIONATM + UNO);
	memset(ptrStationCode, ZERO, SIZE_CODE + UNO);
	memset(ptrSampleCode, ZERO, SIZE_CODE + UNO);
	memset(ptrDate, ZERO, SIZE_DATE + UNO);
	memset(ptrDrct, ZERO, SIZE_DRCT + UNO);
	memset(ptrDwpt, ZERO, SIZE_DWPT + UNO);
	memset(ptrHght, ZERO, SIZE_HGHT + UNO);
	memset(ptrMixr, ZERO, SIZE_MIXR + UNO);
	memset(ptrPres, ZERO, SIZE_PRES + UNO);
	memset(ptrRelh, ZERO, SIZE_RELH + UNO);
	memset(ptrSknt, ZERO, SIZE_SKNT + UNO);
	memset(ptrTemp, ZERO, SIZE_TEMP + UNO);
	memset(ptrThta, ZERO, SIZE_THTA + UNO);
	memset(ptrThte, ZERO, SIZE_THTE + UNO);
	memset(ptrThtv, ZERO, SIZE_THTV + UNO);

	esquema = this->getSchema();

	RecordHandler::REG_GET(registro, esquema, "PKConditionAtm, stationCode, sampleCode, date, drct, dwpt, hght, mixr, pres, relh, sknt, temp, thta, thte, thtv", ptrPKConditionAtm, ptrStationCode, ptrSampleCode, ptrDate, ptrDrct, ptrDwpt, ptrHght, ptrMixr, ptrPres, ptrRelh, ptrSknt, ptrTemp, ptrThta, ptrThte, ptrThtv);
	
	this->PKConditionAtm.clear();
	this->PKConditionAtm += ptrPKConditionAtm;
	
	this->stationCode.clear();
	this->stationCode += ptrStationCode;
	
	this->sampleCode.clear();
	this->sampleCode += ptrSampleCode;
	
	this->date.clear();
	this->date += ptrDate;

	this->drct.clear();
	this->drct += ptrDrct;

	this->dwpt.clear();
	this->dwpt += ptrDwpt;

	this->hght.clear();
	this->hght += ptrHght;

	this->mixr.clear();
	this->mixr += ptrMixr;

	this->pres.clear();
	this->pres += ptrPres;

	this->relh.clear();
	this->relh += ptrRelh;

	this->sknt.clear();
	this->sknt += ptrSknt;

	this->temp.clear();
	this->temp += ptrTemp;

	this->thta.clear();
	this->thta += ptrThta;

	this->thte.clear();
	this->thte += ptrThte;

	this->thtv.clear();
	this->thtv += ptrThtv;

}

void ConditionAtm::saveInRegistro(void* registro)
{
	campo* esquema = NULL;

	char ptrPKConditionAtm[SIZE_PKCONDITIONATM + UNO];
	char ptrStationCode[SIZE_CODE + UNO];
	char ptrSampleCode[SIZE_CODE + UNO];
	char ptrDate[SIZE_DATE + UNO];
	char ptrDrct[SIZE_DRCT + UNO];
	char ptrDwpt[SIZE_DWPT + UNO];
	char ptrHght[SIZE_HGHT + UNO];
	char ptrMixr[SIZE_MIXR + UNO];
	char ptrPres[SIZE_PRES + UNO];
	char ptrRelh[SIZE_RELH + UNO];
	char ptrSknt[SIZE_SKNT + UNO];
	char ptrTemp[SIZE_TEMP + UNO];
	char ptrThta[SIZE_THTA + UNO];
	char ptrThte[SIZE_THTE + UNO];
	char ptrThtv[SIZE_THTV + UNO];

	memset(ptrPKConditionAtm, ZERO, SIZE_PKCONDITIONATM + UNO);
	memset(ptrStationCode, ZERO, SIZE_CODE + UNO);
	memset(ptrSampleCode, ZERO, SIZE_CODE + UNO);
	memset(ptrDate, ZERO, SIZE_DATE + UNO);
	memset(ptrDrct, ZERO, SIZE_DRCT + UNO);
	memset(ptrDwpt, ZERO, SIZE_DWPT + UNO);
	memset(ptrHght, ZERO, SIZE_HGHT + UNO);
	memset(ptrMixr, ZERO, SIZE_MIXR + UNO);
	memset(ptrPres, ZERO, SIZE_PRES + UNO);
	memset(ptrRelh, ZERO, SIZE_RELH + UNO);
	memset(ptrSknt, ZERO, SIZE_SKNT + UNO);
	memset(ptrTemp, ZERO, SIZE_TEMP + UNO);
	memset(ptrThta, ZERO, SIZE_THTA + UNO);
	memset(ptrThte, ZERO, SIZE_THTE + UNO);
	memset(ptrThtv, ZERO, SIZE_THTV + UNO);

	strncpy(ptrPKConditionAtm, (char*)this->PKConditionAtm.c_str(), SIZE_PKCONDITIONATM );
	strncpy(ptrStationCode, (char*)this->stationCode.c_str(), SIZE_CODE );
	strncpy(ptrSampleCode, (char*)this->sampleCode.c_str(), SIZE_CODE );
	strncpy(ptrDate, (char*)this->date.c_str(), SIZE_DATE );
	strncpy(ptrDrct, (char*)this->drct.c_str(), SIZE_DRCT );
	strncpy(ptrDwpt, (char*)this->dwpt.c_str(), SIZE_DWPT );
	strncpy(ptrHght, (char*)this->hght.c_str(), SIZE_HGHT );
	strncpy(ptrMixr, (char*)this->mixr.c_str(), SIZE_MIXR );
	strncpy(ptrPres, (char*)this->pres.c_str(), SIZE_PRES );
	strncpy(ptrRelh, (char*)this->relh.c_str(), SIZE_RELH );
	strncpy(ptrSknt, (char*)this->sknt.c_str(), SIZE_SKNT );
	strncpy(ptrTemp, (char*)this->temp.c_str(), SIZE_TEMP );
	strncpy(ptrThta, (char*)this->thta.c_str(), SIZE_THTA );
	strncpy(ptrThte, (char*)this->thte.c_str(), SIZE_THTE );
	strncpy(ptrThtv, (char*)this->thtv.c_str(), SIZE_THTV );

	esquema = this->getSchema();

	RecordHandler::REG_SET(registro, esquema, "PKConditionAtm, stationCode, sampleCode, date, drct, dwpt, hght, mixr, pres, relh, sknt, temp, thta, thte, thtv", ptrPKConditionAtm, ptrStationCode, ptrSampleCode, ptrDate, ptrDrct, ptrDwpt, ptrHght, ptrMixr, ptrPres, ptrRelh, ptrSknt, ptrTemp, ptrThta, ptrThte, ptrThtv);

}
const ConditionAtm & ConditionAtm::operator=(const ConditionAtm& p)
{
	PKConditionAtm = p.PKConditionAtm;
	stationCode = p.stationCode;
	sampleCode = p.sampleCode;
	date = p.date;
	drct = p.drct;
	dwpt = p.dwpt;
	hght = p.hght ;
	mixr = p.mixr;
	pres = p.pres;
	relh = p.relh;
	sknt = p.sknt;
	temp = p.temp ;
	thta = p.thta;
	thte =p.thte;
	thtv = p.thtv;
	return (*this);
}
XMLNode* ConditionAtm::toViewXML()
{
	XMLNode* node = new XMLNode();
	node->setNombre("CloudLayer");
	node->insertarAtributo("stationCode",this->getStationCode());
	node->insertarAtributo("date",this->getDate());
	node->insertarAtributo("drct",this->getDrct());
	node->insertarAtributo("dwpt",this->getDwpt());
	node->insertarAtributo("hght",this->getHght());
	node->insertarAtributo("mixr",this->getMixr());
	node->insertarAtributo("pres",this->getPres());
	node->insertarAtributo("relh",this->getRelh());
	node->insertarAtributo("sknt",this->getSknt());
	node->insertarAtributo("temp",this->getTemp());
	node->insertarAtributo("thta",this->getThta());
	node->insertarAtributo("thte",this->getThte());
	node->insertarAtributo("thtv",this->getThtv());
	
	return node;	
}

void ConditionAtm::print()
{
	std::cout << "PKCONDITIONATM: " << PKConditionAtm << std::endl;
	std::cout << "STATIONCODE: " << stationCode << std::endl;
	std::cout << "SAMPLECODE: " << sampleCode << std::endl;
	std::cout << "DATE: " << date << std::endl;
	std::cout << "DRCT: " << drct << std::endl;
	std::cout << "DWPT: " << dwpt << std::endl;
	std::cout << "HGHT: " << hght << std::endl;
	std::cout << "MIXR: " << mixr << std::endl;
	std::cout << "PRES: " << pres << std::endl;
	std::cout << "RELH: " << relh << std::endl;
	std::cout << "SKNT: " << sknt << std::endl;
	std::cout << "TEMP: " << temp << std::endl;
	std::cout << "THTA: " << thta << std::endl;
	std::cout << "THTE: " << thte << std::endl;
	std::cout << "THTV: " << thtv << std::endl;
}

